package com.ctec.dataprocess.csv;

import com.ctec.mapper.ClickhouseMapper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@RestController
public class CsvDataController {

    /**
     * 打算导入csv数据
     * <p>
     * <p>
     * create table company
     * (
     * id              Int32,
     * CAT             Nullable(String),
     * COMPANY_NAME    Nullable(String),
     * EMAIL           Nullable(String),
     * ADDRESS         Nullable(String),
     * CITY            Nullable(String),
     * STATE           Nullable(String),
     * ZIPCODE         Nullable(String),
     * PHONE_NUMBER    Nullable(String),
     * FAX_NUMBER      Nullable(String),
     * SIC_CODE        Nullable(String),
     * SIC_DESCRIPTION Nullable(String),
     * WEB_ADDRESS     Nullable(String)
     * )
     * engine = MergeTree() PRIMARY KEY (id) ;
     */

    @Resource
    private ClickhouseMapper clickhouseMapper;



    @Autowired
    private Connection connection;

    @RequestMapping("dodeeee")
    public void dodd() throws SQLException {



        PreparedStatement preparedStatement = connection.prepareStatement("select count(1) from default.company;");
        ResultSet resultSet = preparedStatement.executeQuery();

        // 判断结果集是否有数据，然后提取数据
        if (resultSet.next()) {
            // 由于查询的是count(1)，结果集中只会有一行一列数据，使用getInt方法获取这个整数值（因为count结果一般是整数类型）
            int count = resultSet.getInt(1);
            System.out.println("表default.company中的记录数量为: " + count);
        }
        preparedStatement.close();

        importDataFromCSVFile();


    }

    private void importDataFromCSVFile() throws SQLException {

        //从csv文件中导入数据到Clickhouse

        String sql = "";
        connection.prepareStatement("");


    }


}

